package com.meal.test.schedule;

import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;

/**
 * @Title: ScheTask
 * @Description: 定时任务
 * @Author yangzhanghui
 * @Date 2020/5/89:37
 * @Version v1.0
 */
public class ScheTask {

    //第一次执行开始到第二次之间的时间间隔
    @Scheduled(fixedRate = 2000)
    public void fixedRate(){
        System.out.println(new Date());
    }

    //第一次执行结束到第二次之间的间隔
    @Scheduled(fixedDelay = 2000)
    public void fixedDelay(){
        System.out.println(new Date());
    }

    //首次任务启动的延时时间
    @Scheduled(initialDelay = 2000, fixedRate = 2000)
    public void initialDelay(){
        System.out.println(new Date());
    }

    @Scheduled(cron = "0/5 * * * * *")
    public void cron(){
        System.out.println(new Date());
    }
}
